package com.ehotting.edsta.system.api;

import com.ehotting.eaf.core.constant.ServiceNameConstants;
import com.ehotting.eaf.core.domain.R;
import com.ehotting.eaf.core.domain.system.api.SysFile;
import com.ehotting.edsta.system.api.factory.RemoteFileFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件服务
 * 
 * @author edsta
 */
@FeignClient(contextId = "remoteFileService", value = ServiceNameConstants.FILE_SERVICE, fallbackFactory = RemoteFileFallbackFactory.class)
public interface RemoteFileService
{
    /**
     * 上传文件
     *
     * @param file 文件信息
     * @return 结果
     */
    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    R<SysFile> upload(@RequestPart(value = "file") MultipartFile file);

    /**
     * 上传文件
     *
     * @param file 文件信息
     * @return 结果
     */
    @PostMapping(value = "/uploadByModule", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    R<SysFile> upload(@RequestPart(value = "file") MultipartFile file,
                      @RequestParam("moduleName") String moduleName,
                      @RequestParam("accessKey") String accessKey,
                      @RequestParam("secretKey") String secretKey);

    @GetMapping("/getBytesFromMinio")
    R<byte[]> getBytesFromMinio(@RequestParam("filename") String filename,
                                @RequestParam("moduleName") String moduleName);

    @PostMapping(value = "/uploadByFilepath", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    R<SysFile> uploadByFilepath(@RequestPart(value = "file") MultipartFile file,
                                @RequestParam("bucketName") String bucketName,
                                @RequestParam(name = "filepath") String filepath);
}
